#include "yacc_parser/Conventions.h"
#include "symbol_table/SymbolBase.h"
#include "yacc_parser/IdentifierList.h"

Conventions * Conventions::s_pInstance = NULL;

Conventions::Conventions(void)
{
}


Conventions::~Conventions(void)
{
	std::vector<ConventionItem *>::iterator it;
	for( it = m_oConventions.begin(); m_oConventions.end() != it; ++it)
	{
		delete (*it);
	}

	TypeIdentifierContainer::iterator it1;
	for( it1 = m_oTypedTokens.begin(); m_oTypedTokens.end() != it1; ++it1)
	{

		delete it1->second;
	}
}

Conventions & Conventions::getInstance()
{
	if(s_pInstance)
	{
		s_pInstance = new Conventions();
	}
	return * s_pInstance;
}

void Conventions::addConvention( ConventionItem * pConvention )
{
	m_oConventions.push_back(pConvention);
}

void Conventions::addDefinedToken( IdentifierList *pDefinedToken )
{
	std::vector<SymbolBase *> & tokens = pDefinedToken->getIdentifiers();

	std::vector<SymbolBase *>::iterator it;
	for(it = tokens.begin(); tokens.end() != it; ++ it)
	{
		(*it)->setSymbolType(SymbolBase::defined_token);
		m_oDefinedTokens.push_back((*it));
	}

	delete pDefinedToken;
}

void Conventions::addTypedToken( SymbolBase *pType, IdentifierList *pTokens )
{
	//To fix it!
}

